<template>
  <div class="recommend">
    <div class="banner">
      <van-swipe
        :autoplay="3000"
        indicator-active-color="#9926f7"
        indicator-color="#fff"
        class="swiper"
      >
        <van-swipe-item v-for="item in bannerList" :key="item.id">
          <img
            :src="item.imageUrl"
            class="swiper-image"
            @click="playsong(item)"
          />
        </van-swipe-item>
      </van-swipe>
    </div>
    <recommend-music :recommendList="recommendList"></recommend-music>
    <recommend-newsongs :newsongsList="newsongsList"></recommend-newsongs>
  </div>
</template>

<script>
import {
  getBanner,
  getPersonalized,
  getNewsong,
  getSong,
} from "../api/recommend";
import recommendMusic from "@/components/recommendmusic.vue";
import recommendNewsongs from "@/components/recommendNewsongs.vue";
import { mapMutations } from "vuex";
export default {
  data() {
    return {
      bannerList: [],
      recommendList: [],
      newsongsList: [],
    };
  },
  components: {
    recommendMusic,
    recommendNewsongs,
  },
  methods: {
    ...mapMutations(["xplaysong"]),
    playsong(item) {
      getSong(item.targetId).then((res) => {
        // console.log(res);
        this.xplaysong(res.songs[0]);
      });
    },
  },
  created() {
    getBanner.then((res) => {
      // console.log(res);
      this.bannerList = res.banners;
    });
    getPersonalized.then((res) => {
      this.recommendList = res.result;
    });
    getNewsong.then((res) => {
      // console.log(JSON.parse(JSON.stringify(res)))
      this.newsongsList = res.result;
    });
  },
};
</script>

<style lang="scss" scoped>
.banner {
  margin-top: 80px;
  height: 100px;
  background-color: #9926f7;
  padding: 0 10px;
  padding-top: 10px;
  box-sizing: border-box;

  .swiper {
    height: 150px;
    border-radius: 8px;
    overflow: hidden;
    .swiper-image {
      width: 100%;
      height: 150px;
    }
  }
}
</style>
